<%--
    Document   : loanRequest
    Created on : 04 14, 11, 15:27:20 PM
    Author     : MonicaSandoval
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib  prefix="s" uri="/struts-tags" %>
<%@taglib  prefix="sj" uri="/struts-jquery-tags" %>
<%@taglib  prefix="sjg" uri="/struts-jquery-grid-tags" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>


<div id="editrequest" style="width: 100%">    
    <s:url id="remoteurl" action="approval" />
    <s:url id="editurl" value="editloanapp" />
    <s:url id="loanappurl" value="loanprofile-loanapp.jsp" />
    <script type="text/javascript" src="<s:url value='/struts/js/base/jquery.ui.datepicker.min.js'/>"></script>
        <script type="text/javascript">   
            var y;
            var clicker = 0;
            datePick = function(elem) {
                $(elem).datepicker();
                $("#ui-datepicker-div").css("z-index", 2000);
            }

            $.subscribe("gridCompleteTopics",function() {
                var ids = document.getElementById("selected").value;
                for(var prop in y){
                    jQuery.each(y,function(index, item) {
                        jQuery("#gridtable").jqGrid("setSelection", item);
                    });
                    break;
                }                                     
                
                jQuery.each(ids,function(index, item) {
                    var flag = false;
                    for(var prop in y){
                        if(item == y[prop]){
                            flag = true;
                        }
                    }
                    if(!flag){
                        jQuery("#gridtable").jqGrid("setSelection", item);
                    }                                   
                });
                y = document.getElementById("selected").value;
            });

            $.subscribe('getselectedids', function(event,data) {
                var s = $("#gridtable").jqGrid('getGridParam','selarrrow');
                document.getElementById("selected").value = s;
                document.getElementById("disselected").value = document.getElementById("selected").value;
                check();
            });

            function check(){

                if(document.getElementById("selected").value.length != 0){
                    while(document.getElementById("createReq").hasAttribute("style")){
                        document.getElementById("createReq").removeAttribute("style");
                    }
                    while(document.getElementById("discreateReq").hasAttribute("style")){
                        document.getElementById("discreateReq").removeAttribute("style");
                    }
                    document.getElementById("createReq").style.fontSize = "12px";
                    document.getElementById("discreateReq").style.fontSize = "12px";
                }else{
                    document.getElementById("createReq").style.display = "none";
                    document.getElementById("discreateReq").style.display = "none";
                }
            }

            $.subscribe('showcolumns', function(event,data) {
                $("#gridtable").jqGrid('setColumns',{});
            });

            function customFunc(value, colname){
                var date = new Date();
                var myDate = new Date(value);
                if(myDate <= date){
                    return [false, "Please enter a later date."];
                }else{
                    return [true, ""];
                }
            }

            function formatLink(cellvalue, options, rowObject) {
                return "<a href='<s:property value="loanappurl" />?id="+rowObject["loanverificationid"]+"' onClick='javascript: return openDialog(this)'>" + cellvalue + "</a>";
            }
            function openDialog(e) {
                window.open(e.href, "newWindow");
                return false;
            }
            function proceedButton(){
                if(clicker == 0){
                    document.savereq.submit();
                    clicker++;
                }                
            }
            function cancelButton(){
                $('#dialog').dialog('close');
            }
            function noButton(){
                $('#dialog1').dialog('close');
            }
            function disproceedButton(){
                document.dissavereq.submit();
            }
            function discancelButton(){
                $('#dialog2').dialog('close');
            }
            function disnoButton(){
                $('#dialog3').dialog('close');
            }
        </script>
    <sjg:grid
        id="gridtable"
        caption="Edit Request"
        dataType="json"
        href="%{remoteurl}"
        pager="true"
        autowidth="true"
        height="300"
        gridModel="gridModel"
        rowList="10,15,20"
        rowNum="15"
        rownumbers="false"
        onCompleteTopics="gridCompleteTopics"
        onSelectRowTopics="getselectedids"
        navigatorEditOptions="{height:280,reloadAfterSubmit:false}"
        cellEdit="true"
        cellurl="%{editurl}"
        shrinkToFit="false"
        multiselect="true"
        groupField="['requestname']"
    	groupColumnShow="[false]"
    	groupCollapse="true"
    	groupText="['<b>{0} - {1} Loan Applications</b>']"
    >
        <sjg:gridColumn name="loanverificationid"
                        index="loanverificationid"
                        title="Loan Verification No."
                        key="true"
                        hidedlg="true"
                        hidden="true"
        />
        <sjg:gridColumn name="requestname"
                        index="requestname"
                        title="Request ID"
                        hidedlg="true"
                        hidden="true"
        />
        <sjg:gridColumn name="documentno" 
                        index="docno"
                        title="Document No."
                        formatter = "formatLink"
                        search="true"
                        align="center"
                        cssClass="gridlink"
                        sortable="true"
        />
        <sjg:gridColumn name="borrowername"
                        index="borrowername"
                        title="Borrower Name"
                        align="center"
                        sortable="true"
        />
        <sjg:gridColumn name="amountrequested"
                        index="amountrequested"
                        title="Promissory Note"
                        formatter="currency"
                        align="right"
                        editable="true"
                        edittype="text"
                        editrules="{
                                        number:true,
                                        required:true
                                    }"
        />
        <sjg:gridColumn name="areaname" 
                        index="area"
                        title="Area"
                        align="center"
        />
        <sjg:gridColumn name="releasedate"
                        index="releasedate"
                        title="Specific Date of Release"
                        editable="true"
                        edittype="text"
                        editrules="{
                                        date:true,
                                        required:true,
                                        custom:true,
                                        custom_func:customFunc
                                    }"
                        editoptions="{dataInit:datePick}"
                        formatoptions="{newformat:'m/d/Y'}"
                        align="center"
        />
        <sjg:gridColumn name="borroweraddress"
                        index="raddress"
                        title="Residence Address"
                        align="center"
       />
        <sjg:gridColumn name="businessaddresses"
                        index="baddress"
                        title="Business Address"
        />
        <sjg:gridColumn name="businesstypes" 
                        index="btypes"
                        title="Business Type"
                        align="center"
        />
        <sjg:gridColumn name="collaterals" 
                        index="collaterals"
                        title="Collaterals"
                        align="center"
        />
        <sjg:gridColumn name="firstlast" 
                        index="firstlast"
                        title="Mode of Payment (1st Last)"
                        align="center"
                        edittype="text"
        />
        <sjg:gridColumn name="secondlast"
                        index="secondlast"
                        title="Mode of Payment (2nd Last)"
                        align="center"
                        edittype="text"
        />
        <sjg:gridColumn name="firstlastpn"
                        index="firstlastpn"
                        title="PN Amount (1st Last)"
                        formatter="currency"
                        align="right"
        />
        <sjg:gridColumn name="secondlastpn" 
                        index="secondlastpn"
                        title="PN Amount (2nd Last)"
                        formatter="currency"
                        align="right" />
        <sjg:gridColumn name="auditor" 
                        index="empname"
                        title="Auditor Confirmation"
                        align="center"
        />
</sjg:grid>
<br/>
    <div style="text-align:center">
        <sj:a
            name="showhide"
            id="showhide"
            button="true"
            buttonIcon="ui-icon-wrench"
            cssStyle="font-size:12px"
            onClickTopics="showcolumns"
        >
           Show/Hide Columns
        </sj:a>
    </div>
<hr/>
<sj:dialog
    id="dialog"
    autoOpen="false"
    modal="false"
    title="Approve Loans"
    cssStyle="font-size:12px"
>
    </br>
    Are you sure you want to approve the selected loan application(s)?
    <br />
    
   <s:form name="savereq" action="saveloan">
        <s:textfield name="selected" id="selected" value="" cssStyle="display:none" />
   </s:form>
    <br/><hr/>
    <div style ="text-align: center">
    <sj:a
    name="yes"
    id="yes"
    button="true"
    cssStyle="font-size:12px"
    onclick="proceedButton()"
    >
       Yes
    </sj:a>
   <sj:a
    name="no"
    id="no"
    openDialog="dialog1"
    button="true"
    cssStyle="font-size:12px"
    >
       No
    </sj:a>
   <sj:a
    name="cancel"
    id="cancel"
    button="true"
    cssStyle="font-size:12px"
    onclick="cancelButton()"
    >
       Cancel
    </sj:a>
    </div>
</sj:dialog>
<sj:a
    name="createReq"
    id="createReq"
    openDialog="dialog"
    button="true"
    buttonIcon="ui-icon-check"
    cssStyle="display:none"
>
   Approve Loan Applications
</sj:a>
   
<sj:dialog
    id="dialog1"
    autoOpen="false"
    modal="false"
    title="Exiting"
    cssStyle="font-size:12px"
>
    <br/>
 Are you sure you don't want to save the loans?<br /><br/><hr/>
 <div style ="text-align: center">
   <sj:a
    name="yes2"
    id="yes2"
    button="true"
    cssStyle="font-size:12px"
    href="/loanapproval.jsp?cat=request"
    >
       Yes
    </sj:a>
   <sj:a
    name="no2"
    id="no2"
    button="true"
    cssStyle="font-size:12px"
    onclick="noButton()"
    >
       No
    </sj:a>
 </div>
</sj:dialog>
       
       <!--disapprove-->
<sj:dialog
    id="dialog2"
    autoOpen="false"
    modal="false"
    title="Disapprove Loans"
    cssStyle="font-size:12px"
>
    <br/>
    Are you sure you want to disapprove the selected loan application(s)?
    <br />
   <s:form name="dissavereq" action="saveloandis">
        <s:textfield name="disselected" id="disselected" value="" cssStyle="display:none" />
   </s:form>
    <br/><hr/>
    <div style ="text-align: center">
    <sj:a
    name="disyes"
    id="disyes"
    button="true"
    cssStyle="font-size:12px"
    onclick="disproceedButton()"
    >
       Yes
    </sj:a>
   <sj:a
    name="disno"
    id="disno"
    openDialog="dialog3"
    button="true"
    cssStyle="font-size:12px"
    >
       No
    </sj:a>
   <sj:a
    name="discancel"
    id="discancel"
    button="true"
    cssStyle="font-size:12px"
    onclick="discancelButton()"
    >
       Cancel
    </sj:a>
</div>
</sj:dialog>
<sj:a
    name="discreateReq"
    id="discreateReq"
    openDialog="dialog2"
    button="true"
    buttonIcon="ui-icon-close"
    cssStyle="display:none"
>
   Disapprove Loan Applications
</sj:a>
   
<sj:dialog
    id="dialog3"
    autoOpen="false"
    modal="false"
    title="Exiting"
    cssStyle="font-size:12px"
>
    </br>
 Are you sure you don't want to save the loans?<br /><br/><hr/>
 <div style="text-align: center">
   <sj:a
    name="disyes2"
    id="disyes2"
    button="true"
    cssStyle="font-size:12px"
    href="/loanapproval.jsp?cat=request"
    >
       Yes
    </sj:a>
   <sj:a
    name="disno2"
    id="disno2"
    button="true"
    cssStyle="font-size:12px"
    onclick="disnoButton()"
    >
       No
    </sj:a>
 </div>
</sj:dialog>
</div>
